package club.ruanx.auth.vcode.image;

import club.ruanx.auth.vcode.ImageCodeProperties;
import club.ruanx.auth.vcode.factory.ValidateCodeGenerator;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author 阮胜
 * @date 2018/9/30 13:08
 */
public class ImageCodeGenerator implements ValidateCodeGenerator {

    @Autowired
    private ImageCodeProperties imageCodeProperties;

    @Override
    public ImageCode generate() {
        ValidateCodeUtil.ValidateImageCode imageCode = ValidateCodeUtil.generate(imageCodeProperties.getWidth(),
                imageCodeProperties.getHeight(), imageCodeProperties.getVcodeLength(), imageCodeProperties.getLineCount());
        return new ImageCode(imageCode.getCode(), imageCodeProperties.getExpiredInSeconds(), imageCode.getImage());
    }

}
